<?php



namespace app\modules\admin\models;

use Yii;
use yii\web\IdentityInterface;
use yii\helpers\Url;
use yii\base\Exception;
/**
 * ContactForm is the model behind the contact form.
 */

class SendMobileMsg
{
    private $url = 'http://211.152.44.152:8000/api/SendMsg/SendMessageWithUOLeem'; //短信接口地址


    //发送短信验证码
    public  function messagecheckcode($phone,$message){

        $params = array(
            "phone" => $phone,//
            "Message" => '验证码是：'.$message.',欢迎使用“车去车来”互联网爱车共享平台,分享闲置,愉悦出行.服务热线：4006121121.',//
        );

        try {
            $paramstring = http_build_query($params);
            $result = $this->juhecurl($this->url,$paramstring);

        }  catch (\Exception $ex) {
            $result['err_code'] = 40017;
            $result['err_msg'] = $ex->getMessage(); //  服务器错误
            return $result;
        }
        return $result;
    }


    function  juhecurl($url,$params=false,$ispost=0){
        $httpInfo = array();
        $ch = curl_init();

        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
     //   curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            //echo "cURL Error: " . curl_error($ch);
            return false;
        }
        $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
        $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
        curl_close( $ch );
        return $response;
    }

}


